package com.lbn.jfqsc.app.account.order;

import com.lbn.baseframe.mvp.BasePresenter;
import com.lbn.baseframe.net.business.RxSubscribe;
import com.lbn.jfqsc.App;
import com.lbn.jfqsc.app.ListMvp;
import com.lbn.jfqsc.business.bean.JobList;
import com.lbn.jfqsc.business.bean.OrderList;
import com.lbn.jfqsc.business.bean.SupportList;
import com.lbn.jfqsc.net.Host;

import java.util.List;

/**
 * Created by 李炳南
 * 2017/3/1.
 */

public class OrderPresenter extends BasePresenter<ListMvp> {

    public void supportList(final int page) {

        subscribeNetwork(Host.getApi().supportList(App.getUser().getId(), page), new RxSubscribe<List<SupportList>>() {
            @Override
            public void next(List<SupportList> o) {
                if (page == 1) {
                    getView().setData(o);
                } else {
                    getView().addData(o);
                }

                if (o.size() < 10) {
                    getView().isMore(false);
                } else {
                    getView().isMore(true);
                }
            }

            @Override
            public void error(Throwable e) {
                getView().onError(e.getMessage());
            }
        });
    }

    public void orderList(final int page) {

        subscribeNetwork(Host.getApi().orderList(App.getUser().getId(), page), new RxSubscribe<List<OrderList>>() {
            @Override
            public void next(List<OrderList> o) {
                if (page == 1) {
                    getView().setData(o);
                } else {
                    getView().addData(o);
                }

                if (o.size() < 10) {
                    getView().isMore(false);
                } else {
                    getView().isMore(true);
                }
            }

            @Override
            public void error(Throwable e) {
                getView().onError(e.getMessage());
            }
        });
    }

}
